package com.yjn.baidumap_hello;

import android.app.Activity;
import android.os.Bundle;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

public class MainActivity extends Activity {
	// 定位服务的客户端。宿主程序在客户端声明此类，并调用
	private LocationClient mLocationClient;
	public BDLocationListener myListener = new MyLocationListener();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mLocationClient = new LocationClient(getApplicationContext()); // 声明LocationClient类
		//设置定位参数
		LocationClientOption option = new LocationClientOption();
		option.setLocationMode(option.getLocationMode().Hight_Accuracy);//设置定位模式
		option.setCoorType("bd09ll");//返回的定位结果是百度经纬度，默认值gcj02
		int span=5000;
		option.setScanSpan(span);//设置发起定位请求的间隔时间为5000ms
		//设置是否需要地址信息，默认为无地址
		option.setIsNeedAddress(true);
		mLocationClient.setLocOption(option);
		mLocationClient.registerLocationListener(myListener); // 注册监听函数
		mLocationClient.start();
	}
	/**
	 * 实现实位回调监听
	 */
	public class MyLocationListener implements BDLocationListener {
		@Override
		public void onReceiveLocation(BDLocation location) {
			System.out.println(">>>X:" + location.getLatitude());
			System.out.println(">>>Y:" + location.getLongitude());
			System.out.println(">>>所在城市:" + location.getCity() );
			System.out.println(">>>详细地址信息:" + location.getAddrStr());
		}

	}

}
